<?php
    header("Content-Type:text/html; charset=utf-8");
    $loginName = $_POST["loginName"];
    $password = $_POST['password'];

    //处理请求，获取到用户名及密码，到数据库里面查询，有没有这样一条　记录，有就登录成功
    //否则就是用户名或密码错误；

    //建立数据库连接，
    $con = mysqli_connect("127.0.0.1","root","","xxy");
    //判断是否已经建立链接
    if(!$con){
        printf("Can't connect to MySQL Server. Errorcode: %s ",mysqli_connect_error());
        exit;
    }
    $sql = "SELECT * FROM employee WHERE loginName='$loginName' and password='$password'";
    //响应一个结果
    $result = mysqli_query($con,$sql);
    $item = array();
    //获取这个结果
    if($row = mysqli_fetch_array($result)){
        //怎么拿到数据
        //$row代表的是一行数据
        $item = array(
            "id" =>  $row["id"],
            "username" => $row["username"],
            "password" => $row["password"],
            "loginName" => $row["loginName"]
        );
    }

    //根据结果进行判断输出
    if(count($item)>0){
        echo "登录成功";
    }else{
        echo "登录失败";
    }

    //关闭连接
    mysqli_close($con);
?>